package com.turing.usdtpay.mvp.presenter;

import com.turing.usdtpay.http.ApiService;
import com.turing.usdtpay.http.ApiUrl;
import com.turing.usdtpay.http.callback.ApiCallback;
import com.turing.usdtpay.http.entity.ResponseDate;
import com.turing.usdtpay.mvp.contract.FindPwdContract;

import java.util.HashMap;

/**
 * @作者：JAY
 * @创建时间：2019/10/23 14:27
 * @描述：
 **/
public class FindPwdPresenter implements FindPwdContract.Present {
    private FindPwdContract.View mView;

    public FindPwdPresenter(FindPwdContract.View view) {
        this.mView = view;
    }



    @Override
    public void sendCode(String email, int type) {
        HashMap<String,String> map = new HashMap<>();
        map.put("act",email);
        map.put("type",type+"");
        ApiService.getInstance().postRequest(ApiUrl.API_GET_EMAIL_CODE, map, new ApiCallback() {
            @Override
            public void onSuccess(int code, ResponseDate date) {
                if (date.getRet() == 1){
                    mView.sendSuccess();
                }else {
                    mView.onFail(date.getMsg());
                }
            }

            @Override
            public void onFailure(Throwable exception) {
                mView.onFail(exception.getMessage());
            }
        });

    }

    @Override
    public void resetPwd(String email,String pwd, String code) {
        HashMap<String,String> map = new HashMap<>();
        map.put("act",email);
        map.put("mail_code",code);
        map.put("pwd",pwd);
        ApiService.getInstance().postRequest(ApiUrl.API_RESET_PWD, map, new ApiCallback() {
            @Override
            public void onSuccess(int code, ResponseDate date) {
                if (date.getRet() == 1){
                    mView.resetSuccess();
                }else {
                    mView.onFail(date.getMsg());
                }
            }

            @Override
            public void onFailure(Throwable exception) {
                mView.onFail(exception.getMessage());
            }
        });
    }


}
